<template>
  <div>
    <el-table
      class="marT20"
      :data="tableData"
      :height="300"
      v-loading="loading"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(255, 255, 255, 0.8)"
      @selection-change="onSelect"
    >
      <el-table-column width="70" align="center" type="index" label="序号"></el-table-column>
      <el-table-column
        v-for="item in columns"
        :key="item.prop"
        :prop="item.prop"
        :label="item.label"
        align="center"
      ></el-table-column>
      <el-table-column :label="$t('base.table.action')" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" @click="onDelete(scope.row)">取消关联</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="changePageSize"
      @current-change="changePageNo"
      :current-page="pageNo"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalSize"
    ></el-pagination>
  </div>
</template>

<script>
import curd from "@/mixins/curd";
import { drillAPI as request } from "@/api";
export default {
  mixins: [curd],
  props: ["id"],
  data() {
    return {
      condition: {
        maneuverId: this.id,
      },
      request: {
        page: request.releasexiangdingPage,
        delete: request.unReleaseXiangding,
      },
      columns: [
        { prop: "scenarioName", label: "想定名称" },
        { prop: "scenarioStatusText", label: "状态" },
        { prop: "scenarioCreateTime", label: "创建时间" },
      ],
    };
  },
  methods: {
    formatTableData(tableData) {
      tableData.forEach((el) => {
        el.scenarioStatusText = "";
        el.scenarioReleaseStatusText = "";
        if (el.scenarioReleaseStatus == 0) {
          el.scenarioReleaseStatusText = "未关联";
        } else if (el.scenarioReleaseStatus == 1) {
          el.scenarioReleaseStatusText = "已关联";
        }

        if (el.scenarioStatus == 0) {
          el.scenarioStatusText = "禁用";
        } else if (el.scenarioStatus == 1) {
          el.scenarioStatusText = "启用";
        }
      });
    },
    // 取消关联想定
    onDelete(rowItem) {
      this.$confirm("确认取消关联想定？", this.$t("base.tooltip"), {
        confirmButtonText: this.$t("base.button.ok"),
        cancelButtonText: this.$t("base.button.cancel"),
        type: "warning",
      })
        .then(() => {
          this.request
            .delete(rowItem.maneuverId, rowItem.scenarioId)
            .then((res) => {
              this.onSearch();
            });
        })
        .catch(() => {});
    },
  },
};
</script>

<style>
</style>
